<? 
	include('base.php');

	User::protect();

	include_class('links');

	$category_id = ($_GET['category_id'] > 0 && is_numeric($_GET['category_id'])) ? $_GET['category_id'] : 0;

	if ($category_id != 0) {
		$lc = LinkCategory::get($category_id);

		if (!db::isError($lc)) { 
			// do nothing
		}
	}

	if ($_POST['submit'] && !db::isError($lc)) {
		$title       = $_POST['title'];
		$description = $_POST['description'];

		if (!$lc) {
			$res = LinkCategory::add($title, $description);
		}
		else {
			$res = $lc->add($title, $description);
		}

		if (!db::isError($res)) {
			header('Location: links.php?category_id=' . $res->getID());
		}
	}

	$editors = array('description');
	$section = 'links';
	$page_title = 'Add Link Category';

	include('layout/header.php');
?>

<div id="breadcrumb">
	<a href="index.php">Audition &#62;</a>
	<a href="links.php">Links &#62;</a>

	<?
	if ($lc) {
		$breadcrumb = $lc->getCategoryTrail();

		if ($breadcrumb) { 
			foreach($breadcrumb as $lcBC) {
				echo('<a href="links.php?category_id=' . $lcBC->getID() . '">' . $lcBC->getName() . ' &#62;</a>');
			}
		}
	}
	?>

	Add Link Category
</div>

<? if (!db::isError($ma)) { 

	if (db::isError($res)) { 
		$res->outputList();
	}
?>

	<h1>new entry:</h1>
	<div class="inset">
	<form id="add_new_entry" action="<?=$_SERVER['PHP_SELF']?>?id=<?=$id?>" method="post">
	<table border="0" class="edit-form" cellspacing="0" cellpadding="0">
	<tr>
		<td width="50%"><strong>Name:</strong><br/>
		<input type="text" class="text" name="title" id="title" value="<?=$_POST['title']?>"></td>
	</tr>
	</table>
	<div class="edit-form">
		<strong>Description</strong><br/><textarea name="description" id="description" value="" class="full"><?=$_POST['description']?></textarea></td>
	</div>
	<div class="edit-form">
		<input type="submit" value="Add Category" name="submit" class="button">
		<input type="submit" value="Return to Previous Category" name="preview" onclick="location.href='links.php?category_id=<?= $category_id ?>'; return false" class="button"></td>
	</div>
	</div>

<? } else { ?>

	<?=$ma->outputDialog('Return to Links','links.php');?>
		
<? } ?>

<? include('layout/footer.php'); ?>
